<template>
  <div>
    <el-dialog
      title="选择用户"
      :visible="visible"
      width="40%"
      @close="visible = false"
      :close-on-click-modal="false"
    >
      <el-table
        ref="singleTable"
        :data="selections"
        @current-change="handleCurrentChange"
        @selection-change="handleSelectionChange"
        style="width: 100%;height:40vh"
      >
      
        <el-table-column type="selection" width="50"> </el-table-column>
        <el-table-column type="index" width="50"> </el-table-column>
         <el-table-column property="name" label="名称"  width="220" > </el-table-column>
        <el-table-column property="id" label="ID">
        </el-table-column>
       
      </el-table>

      <span slot="footer" class="dialog-footer">
        <el-button @click="visible = false" size="small">取 消</el-button>
        <el-button type="primary" @click="confirm" size="small"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  props: {
    
  },
  watch: {
    visible(newVal, oldVal) {
      if (!newVal && oldVal) this.hide();
    }
  },
  model: {
    prop: "value",
    event: "change"
  },
  data() {
    return {
      loading: false,
      visible: false,
      defaultLabelWidth: "150px",
      form: {
        name: ""
      },
      rules: {
        name: [{ required: true, message: "请输入", trigger: "change" }]
      },
      currentRow: null,
      selections: [],
      value:{},
      multipleSelection: []
    };
  },
  methods: {
    confirm() {
      this.commit();
    },
    show(value) {
      this.visible = true;
      this.loadData(value);
    },
    hide() {
      this.visible = false;
      this.form = {
        name: ""
      };
    },
    loadData(value) {
      this.loading = true;
      this.value = value;
      this.getUserSelectionsOfUserSelector(value.selectorId).then(() => {
        this.loading = false;
      });
    },
    getUserSelectionsOfUserSelector(selectorId) {
      return this.$store
        .dispatch("workflow/getUserSelectionsOfUserSelector", {userSelectorId:selectorId})
        .then(res => {
          console.log(res);
          this.selections = res;
        });
    },
    commit() {
      const _this = this;
      if (this.multipleSelection.length==0) {
        this.$message({
          message: "警告，请选择！",
          type: "warning"
        });
        return;
      }
      this.$emit("ok-click", {index:this.value.index,value:this.multipleSelection});
      this.hide();
    },
    handleCurrentChange(val) {
      this.currentRow = val;
    },
    handleSelectionChange(val) {
      debugger
        this.multipleSelection = val;
      }
  }
};
</script>

<style></style>
